package com.mr.pay.service;

import java.util.List;

import com.mr.pay.Const;
import com.mr.pay.dao.PayDao;
import com.mr.pay.domain.Cust;
import com.mr.pay.domain.CustLine;
import com.skysz.framework.dao.DomainDao;
import com.skysz.framework.service.AbstractBaseService;

public class PayService extends AbstractBaseService<Cust> {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6080752053800050996L;
	
	private PayDao<Cust> payDao;

	public void setPayDao(PayDao<Cust> payDao) {
		this.payDao = payDao;
	}

	@Override
	public DomainDao<Cust> getDomainDao() {
		return this.payDao;
	}
	
	
	/**
	 * 根据手机号码加载有效的客户信息
	 * @param phone
	 * @return
	 */
	public Cust loadCustByPhone(String phone) {
		String hql = "select c from Cust c where c.phone = ? and c.enable = ?";
		return (Cust) this.utilsDao.loadObject(hql,new Object[]{phone,Boolean.TRUE});
	}
	
	/**
	 * 根据手机号码加载出飞持卡顾客类型的所有会员卡
	 * @param phone
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<CustLine> findCustLineList(String phone) {
		StringBuffer hql = new StringBuffer();
		hql.append("select l");
		hql.append(" from CustLine l left join fetch l.card,Cust c");
		hql.append(" where l.cust.id = c.id");
		hql.append(" and c.phone = ?");
		hql.append(" and l.cardType != ?");
		hql.append(" order by l.cardType,l.id");

		return this.utilsDao.find(hql.toString(),new Object[]{phone,Const.CARD_TYPE_NOCARD});
	}

}
